﻿using CSharpDesign.DAL;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;

namespace CSharpDesign.BLL
{
    public class AdminListService
    {
        SqlHelper data = new SqlHelper();
        public string SelectAdmin(int iCount, string count)
        {
            string strTop = "";

            if (iCount > 1)
            {

                strTop = "top " + count;
            }
            string sql = "select  " + strTop + "  * from [Admin] ";
            return sql;
        }
        public void Color(GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#f6f6f6',this.style.fontWeight='';");
                //当鼠标离开的时候 将背景颜色还原的以前的颜色 
                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
            }
            //单击行改变行背景颜色 
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onclick", "this.style.backgroundColor='#f6f6f6'; this.style.color='buttontext';this.style.cursor='default';");
            }
        }
        public string DeleteAdmin(string ID)
        {
            SqlHelper mydata = new SqlHelper();
            if (int.Parse(data.ReturnSql("select count(*) from  Admin ")) <= 1)
            {
                return "必须保留一个账号！！";
            }
            else
            {
                mydata.RunSql("delete  from Admin  where  id='" + ID + "'");
                return "删除成功！";

            }
        }
    }
}